package com.zhuliwei.controller;

import com.zhuliwei.annotation.SystemLog;
import com.zhuliwei.domain.ResponseResult;
import com.zhuliwei.domain.dto.UpdatePasswordDto;
import com.zhuliwei.domain.dto.UserForgetDto;
import com.zhuliwei.domain.entity.User;
import com.zhuliwei.service.EmailService;
import com.zhuliwei.service.UserService;
import io.swagger.annotations.Api;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * 用户信息接口
 *
 * @author 朱力维
 * @time 2022/10/14 15:20
 **/
@RestController
@RequestMapping("/user")
@Api(tags="用户",description = "用户相关接口")
public class UserController {
    @Resource
    private UserService userService;

    @Resource
    private EmailService emailService;

    // 如果让前端把用户Id传过来 这是不安全的 所以不需要参数
    @GetMapping("/userInfo")
    public ResponseResult userInfo(){
       return userService.userInfo();
    }

    @PutMapping("/userInfo")
    @SystemLog(businessName = "更新用户信息")
    //传回来的是Json格式 需要加上requestBody注解
    public ResponseResult updateUserInfo(@RequestBody User user){
        return userService.updateUserInfo(user);
    }

    @PostMapping("/register")
    public ResponseResult register(@RequestBody User user){
        return userService.register(user);
    }

    @PutMapping("/forget")
    public ResponseResult forgetPassword(@RequestBody UserForgetDto userDto){
        return userService.forgetPassword(userDto);
    }

    @PutMapping("/update")
    public ResponseResult updatePassword(@RequestBody UpdatePasswordDto userDto){
        return userService.updatePassword(userDto);
    }

    @GetMapping(value = {"/getEmailAuthCode/{email}", "/getEmailAuthCode"})
    public ResponseResult getEmailAuthCode(@PathVariable(required = false) String email){
        return emailService.getEmailAuthCode(email);
    }
}
